#!/bin/bash

#=======================================================================
# Do stuff with the .po files in Subversion.
# File ID: 3140ae52-a724-11de-a9b3-00248cd5cf1e
#=======================================================================

echo Kjører en forenkla greie.
cd ~/src/git/other/svn/ || { chdir: Funka ikke.; exit 1; }
[ -d .git/. ] || { echo Finner ikke .git/.; exit 1; }
[ "`pwd`" = "/home/sunny/src/git/other/svn" ] || { echo `pwd`: Er ikke riktig katalog.; exit 1; }
echo pwd = `pwd`
echo ===== git diff HEAD
git diff HEAD
echo -n Trykk Enter for å renske katalogen...
read
echo ===== git clean osv
git clean -fxd
git co -f

echo ===== git co master
git co master
echo ===== git svn rebase
git svn rebase
echo -n Trykk Enter...
read
echo ===== git co nb-po
git co nb-po
echo ===== git rebase master
git rebase master || { echo git rebase gikk på ræva, fiks opp i greiene.; exit 1; }

echo -n Trykk Enter hvis det ser OK ut...
read
./autogen.sh
./configure
make locale-gnu-po-update PO=nb
exit 0

if [ -d .svn/. ]; then
    svnrev=`svnversion .|tr -d M`
else
    svnrev=`git svn find-rev $(git show --format=format:%H | head -1)`
fi
if [ -z "$svnrev" ]; then
    svnrev=`date -u +"%Y%m%dT%H%M%SZ"`
fi
if [ "$1" = "trunkmerge" ]; then
    [ -e HACKING ] || { echo "Du må stå i toppen av arbeidskopien til 1.x.x eller 1.x.x ." >&2; exit 1; }
    echo ======== svn update
    svn up
    cp -p subversion/po/nb.po subversion/po/.etter0_original
    echo ======== ./configure, etc...
    ./autogen.sh && ./configure --prefix=/usr/local/varprg/subversion-1.6.x.r$svnrev --enable-maintainer-mode --disable-shared --with-ssl && make locale-gnu-po-update PO=nb
    cd subversion/po || { echo "cd subversion/po: Nehei." >&2; exit 1; }
    cp -p nb.po .etter1_make
    rm `ls | grep -v -e '^nb.po$' -e 'subversion.pot'`
    svn up -r$svnrev
    echo ======== po-merge.py
    svn cat http://svn.collab.net/repos/svn/trunk/subversion/po/nb.po | po-merge.py nb.po
    cp -p nb.po .etter2_po-merge
    cd ../..
    [ -e HACKING ] || { echo "I alle dager. Skulle liksom være tilbake på toppen av AK-en, men er visst ikke det." >&2; exit 1; }
    echo ======== make locale-gnu-po-update PO=nb
    make locale-gnu-po-update PO=nb
    cd subversion/po || { echo "cd subversion/po: Nehei II." >&2; exit 1; }
    rm `ls | grep -v -e '^nb.po$' -e 'subversion.pot'`
    cp -p nb.po .etter3_make
    echo ======== svn up -r$svnrev
    svn up -r$svnrev
    echo ======== msgfmt
    msgfmt -cv nb.po
elif [ "$1" = "update" ]; then
    ./autogen.sh && \
    ./configure --prefix=/usr/local/varprg/subversion-trunk.r$svnrev \
      --enable-maintainer-mode --disable-shared --with-ssl && \
    make locale-gnu-po-update PO=nb
else
    cat <<END

Syntax: svn-po [command]

Commands:

  trunkmerge
    Merge all new messages from trunk to the current branch.
  update
    Update subversion/po/nb.po .

END
fi
